package ma.ensao.evalmetrics.controller.metrics;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/*
* M�trique pour mesurer l�h�ritage
* Calcule DIT : mesure la profondeur de l�h�ritage d�une classe donn�e
*/
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaSource;

public class DITManager {
	int cmt = 0;
	int w = 0;
	ArrayList<String> list = new ArrayList<>();
	JavaClass[] javaClass;
	int[] tail;

	public DITManager() {

	}

	public int read(File file,JavaClass jc,JavaDocBuilder builder,JavaSource src) {
		// TODO Auto-generated method stub
		int i = 0;
		
		File f = file;
		jc.getName().toString().equals("Object.java");
		
		while (!jc.getName().contains("Object")) {

			i++;
			String abso = file.getPath();
			if(jc.getSuperJavaClass() ==null){
				break;
			}
			String path = jc.getSuperJavaClass().getName().replace(".", "\\")
					.concat(".java");
			if(!jc.getSuperJavaClass().getName().contains(".")){
				path=jc.getPackageName().concat(".").concat(jc.getSuperJavaClass().getName()).replace(".", "\\")
						.concat(".java");
			}
			
			while(!f.getName().equals("src")){
				f=f.getParentFile();
			}
			abso = f.getPath().concat("\\").concat(path);
			if(!new File(abso).exists())
				break;
			if (abso.contains("Object"))
				break;
			f = new File(abso);

			try {
				builder.addSource(f);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			src = builder.getSources()[i];
			jc = src.getClasses()[0];

		}
		return i;
	}

	public static void main(String[] args) throws IOException {

		File file = new File("C:/Users/sam/Desktop/RatRoidClient/src/com/hicham/ratroid/A.java");
		try {
			DITManager a = new DITManager();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}